<!--
 * @Author: lmk
 * @Date: 2021-11-24 15:03:13
 * @LastEditTime: 2021-12-06 17:24:40
 * @LastEditors: lmk
 * @Description: 
-->
<template>
	<view :class="currentTheme">
		<a-nabbar :name="option.label" />
		<view class="sticky-tabs " >
			<me-tabs v-model="indexCurrent" @tabTop="getTabTop" :height="88" :tabs="tabs" @change="tabGetChange" activeColor="#765CFE"></me-tabs>
		</view>
		<swiper v-if="isShow" :indicator-dots="false" :autoplay="false" :style="swiperStyle"  :duration="300" :current="tabIndex" @change="getChange">
			<swiper-item  v-for="(a,b) in tabs" :key="b" >
				<mescroll-item :tabIndex="b" :form="a" @changeTab="getTabChangeIndex" ref="mescroll"></mescroll-item>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	import { deleteIds ,customRequest} from '@/api/crud.js'
	import {mapGetters} from 'vuex'
	import MescrollItem from "./swiperItem.vue";
	import swiperList from '@/mixins/swiperList.js'
	import pageMixins from '@/pages/pageMixins.js'
	import data from '@/data/index.js'
	export default {
		mixins:[swiperList,pageMixins],
		components: {
			MescrollItem
		},
		data() {
			return {
				tabs:[],
				apiModule:'shopApi',
				apiType:'storeOrder',
				isShow:true,
				option:{},
			}
		},
		onHide() {
			this.isShow = false;
		},
		onShow() {
			this.isShow = true;
		},
		onLoad(option) {
			//tabs  如果是票务订单 除了1、2、3、5 都展示    如果不是票务订单 那就根据身份来展示tab : 发行不展示0、5 店家全部展示
			this.tabs = option.type==='ticket' ? data.orderList.filter(val=>![1,2,3,5].includes(val.orderStatus)) : {
				store:data.orderList,
				issue:data.orderList.filter(val=>![0,5].includes(val.value))
			}[this.loginForm.userType || 'store']
			this.tabs = this.tabs.map(val=>{
				val.productType = option.type || 'script,groupBuy,1111'
				return val;
			})
 			const tabIndex = 0;
			this.option = option;
			this.tabGetChange(tabIndex)
			this.indexCurrent = tabIndex;
		},
		methods: {
			//获取需要更新的orderStatus 来获取tab的下标
			getTabChangeIndex(tabIndexArr) {
				const refs = this.$refs.mescroll;
				if(this.tabIndex!=0){ // 如果当前选中的tab不是选中的全部
					refs[0].mescroll.resetUpScroll() // 手动更新全部这个tab
				}
				this.tabs.forEach((val,index)=>{
					const resetFlag = tabIndexArr.some(item=>item==val.orderStatus)
					if(resetFlag){
						const ref = refs[index];
						ref.mescroll.resetUpScroll() // 更新需要更新的tab数据
					}
				})
				console.log(this.tabs,tabIndexArr)
			}
		},
		filters:{
			statusName(val){
				const {name} = tabs.find(item=>item.value===val);
				return name
			}
		}
	}
</script>